<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2023-01-06 13:47:30
 * @LastEditors: 陈妮娜 969682281@qq.com
 * @LastEditTime: 2024-03-22 16:19:44
 * @FilePath: \mould\src\views\pages\Supervision\deliverability.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left" style="width: 100%">
          <vDatePicker
            :defaultDate="value2"
            @selectPickDate="selectTime"
            width="215px !important"
          >
          </vDatePicker>
          <!-- <el-date-picker @change="selectTime" v-model="value2" type="daterange" align="right" unlink-panels
                                                                                                                                                                    range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"
                                                                        format="yyyy-MM-dd" value-format="yyyy-MM-dd">
                                                                    </el-date-picker> -->
          <!-- <el-select class="selectBhz" style="width: 160px" v-model="getList.machineId" placeholder="所有拌和机"
                                                                        @change="yj_searchForm(getList)">
                                                                        <el-option v-for="v in bhjDataList" :key="v.fItemName" :label="v.fItemName" :value="v.fItemValue">
                                                                            </el-option>
                                                                        </el-select> -->
          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.stationId"
            placeholder="所有拌和站"
            @change="selectBhz"
          >
            <el-option
              v-for="v in bhzDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>

          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.machineId"
            placeholder="所有拌和机"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in bhjDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
        </div>
        <!-- 顶部按钮 -->
        <div class="print"></div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <div class="materialTable" style="height: 130px">
          <tableData
            v-if="table_config.thead.length > 1"
            :config="table_config"
            :dataList="tableData"
            :loading="listLoading"
            @selection-change="selectionChange"
            @sort-change="sortChange"
          />
        </div>
        <div class="materialCharts">
          <myCharts
            :time1="this.value2[0]"
            :time2="this.value2[1]"
            :commonData="chartsData"
          >
          </myCharts>
        </div>
        <!-- <div :id="('select' + index)" v-for="(item, index) in tableData" :key="index">12</div> -->
      </div>
    </div>
  </div>
</template>

<script>
import vDatePicker from "@/components/public/v-DatePicker";
import tree from "@/components/public/el-trees"; //左侧机构树
import TableData from "@/components/public/el-table"; //主页面列表
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import myCharts from "@/components/public/outputCharts";
import {
  getUserCompanyTreeList, //左侧机构树接口
  getConcreteProduction, //查询-混凝土产量分析
  getStationmachineList, //拌合站列表
  getMachineListByStationId, //拌合机
} from "@/api/request.js";

export default {
  name: "output",
  data() {
    return {
      name: "output", //按钮配置页面代号
      // yj_view: null, //查看按钮是否显示
      formData: {}, //新增编辑向后台传递对象
      bhjDataList: [], //拌合机
      bhzDataList: [], //拌合站
      value2: "", //主页面日期筛选绑定值
      // 列表配置项
      table_config: {
        imgKeyWord: "url",
        fileKeyWord: "url",
        fileName: "fFileName",
        dialogHeight: "",
        thead: [],
        isCheckBox: false,
        isIndex: false,
        isOperation: true,
        // 表格操作列
      },
      tableData: [], //表格列表数据列表
      chartsData: {}, //echarts数据
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",

      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      // 列表给后端传参
      getList: {
        companyId: "", // 施工标段id
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        beginDates: "", //上传--开始
        overDates: "", // 上传--结束
        machineId: "", // 拌和机编号
        enCode: "",
        stationId: "",
      },
      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据
      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [],
      userInfo: {}, //登录用户
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
    };
  },
  components: {
    vDatePicker, //时间选择器
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑

    myCharts,
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    if (JSON.parse(sessionStorage.getItem("getLists"))) {
      var data = JSON.parse(sessionStorage.getItem("getLists"));
      this.getList.companyId = data.fCompanyid; // 施工标段id
      this.getList.startDates = data.startDates; // 开始时间
      this.getList.endDates = data.endDates; // 截至时间
      this.getList.beginDates = data.beginDates; // 上传---开始时间
      this.getList.overDates = data.overDates; // 上传---截至时间
      this.getList.machineId = data.machineId; // 拌和机编号
      this.getList.stationId = data.stationId;
      this.getbhjDataMethods(this.getList.stationId);
    }
    if (JSON.parse(sessionStorage.getItem("treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    this.getTree();
    this.btnRole(this.name);
    this.getDate();
  },

  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },

    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "1", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("treeCheck")
              ).fShortname;

              this.getList.companyId = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.checkData[0] = this.treeData[0].fCompanyid;

              this.getList.companyId = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }
            this.mixingPlantList("0", this.getList);
            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      if (JSON.parse(sessionStorage.getItem("getLists"))) {
        var datas = JSON.parse(sessionStorage.getItem("getLists"));
        this.getList.companyId = data.fCompanyid;
        this.getList.startDates = datas.startDates; // 开始时间
        this.getList.endDates = datas.endDates; // 截至时间
        this.value2 = [this.getList.startDates, this.getList.endDates];
      } else {
        this.getList.companyId = data.fCompanyid;
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }
      this.getList.beginDates = ""; // 上传---开始时间
      this.getList.overDates = ""; // 上传---截至时间
      this.getList.machineId = ""; // 拌和机编号
      this.getList.stationId = "";
      this.mixingPlantList("0", this.getList);
      this.yj_searchForm(this.getList);
    },
    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      window.sessionStorage.setItem("getLists", JSON.stringify(data));
      var sc = {
        companyId: data.companyId, // 施工标段id
        startDates: data.startDates, // 开始时间
        endDates: data.endDates, // 截至时间
        machineId: data.machineId, // 拌和机编号
        enCode: "",
        stationId: data.stationId,
      };

      getConcreteProduction(sc)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            var StrengthGrade = []; //强度
            var ActualCalculation = []; //方量
            var DiskNumber = []; // 盘数

            var tableData = [{}, {}];
            var data = res.data.concreteProduction;
            data.map((item) => {
              //数据二次处理
              StrengthGrade.push(item.StrengthGrade); //强度
              ActualCalculation.push(item.ActualCalculation); //方量
              DiskNumber.push(item.DiskNumber); // 盘数
            });
            // 图表数据
            this.chartsData = {
              StrengthGrade: StrengthGrade,
              ActualCalculation: ActualCalculation,
              DiskNumber: DiskNumber,
            };
            this.table_config.thead = [
              {
                label: "强度",
                prop: "type",
                minWidth: "100px",
                align: "center",
              },
            ];
            StrengthGrade.map((item, index) => {
              this.table_config.thead.push({
                label: item,
                prop: item,
                minWidth: "100px",
                align: "center",
              });
              tableData[0].type = "盘数";
              tableData[0][item] = DiskNumber[index];
              tableData[1].type = "方量(m³)";
              tableData[1][item] = ActualCalculation[index];
            });

            that.tableData = tableData;

            // if (res.data.censusList1[0] != null) {
            //     res.data.censusList1[0].type = "盘数";

            //     that.tableData = res.data.censusList1;
            //     // that.tableData[0] = '实际产量'
            // } else {
            //     that.tableData = [];
            // }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 获取拌合站数据
    mixingPlantList(num, datas) {
      // // this.getList.fCompanyid this.checkData[0]
      var data = {
        companyId: datas.companyId, // 施工标段id
        modelType: num, // 类型
        stationType: "1", // 拌合站类型
      };

      // this.bhzDataList = [];
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            // if (num == 1) {
            //   this.bhjDataList = [
            //     {
            //       fItemName: "所有拌和机",
            //       fItemValue: "",
            //     },
            //   ];
            //   arr.map((item) => {
            //     this.bhjDataList.push({
            //       fItemName: item.fMachinename,
            //       fItemValue: item.fMachineid
            //     });
            //   });
            // } else
            // if (num == 0) {
            this.bhzDataList = [
              {
                fItemName: "所有拌和站",
                fItemValue: "",
              },
            ];

            arr.map((item) => {
              this.bhzDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
            console.log(8888, this.bhzDataList);
            // }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 拌合站选择
    selectBhz(e) {
      console.log(e);
      this.getList.machineId = "";
      this.getbhjDataMethods(e);
      // this.yj_searchForm(this.getList)
    },

    getbhjDataMethods(data) {
      getMachineListByStationId({ stationId: data })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            this.bhjDataList = [
              {
                fItemName: "所有拌和机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
            console.log("tttt", this.bhjDataList);
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 时间间隔
    selectTime(e) {
      if (e[0] != "" && e[1] != "") {
        this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
        this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
      } else {
        this.getList.startDates = ""; // 开始时间
        this.getList.endDates = ""; // 截至时间
      }
      this.yj_searchForm(this.getList);
    },

    getDate() {
      if (JSON.parse(sessionStorage.getItem("getLists"))) {
        var data = JSON.parse(sessionStorage.getItem("getLists"));
        this.getList.startDates = data.startDates; // 开始时间
        this.getList.endDates = data.endDates; // 截至时间
        this.getList.machineId = data.machineId; // 拌和机编号
        this.value2 = [this.getList.startDates, this.getList.endDates];
        this.xlsxName =
          this.getList.startDates +
          "至" +
          this.getList.endDates +
          "混凝土拌和站记录数据";
      } else {
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间
        this.getList.beginDates = ""; // 上传---开始时间
        this.getList.overDates = ""; // 上传---截至时间
        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
        this.xlsxName =
          this.common.getDay(-6) +
          "至" +
          this.common.getDay(0) +
          " " +
          "23:59:59" +
          "混凝土拌和站记录数据";
        // this.value2 = [
        //     "2022-11-15 00:00:00",
        //     `${y}-${m}-${d} ${hh}:${mm}:${ss}`,
        // ];
        // this.xlsxName =
        //     `${y}-${m}-01` + "至" + `${y}-${m}-${d}` + "混凝土拌和站记录数据";
      }
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>

<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

/* .baseTitle {
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
} */

.materialCharts {
  height: calc(100% - 110px);
  width: 100%;
}

/* .selectcheckbox {
    margin-left: 15px;
    margin-top: -5px;
    height: 35px;
} */
</style>
